<?php

namespace app\admin\model;

use think\Model;


class ReserveStatistics extends Model
{

    // 表名
    protected $name = 'reserve_record';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'add_time_text',
        'into_time_text',
        'leave_time_text',
        'states_text',
        //'abc',
        //'bbb'
    ];

    public function getStatesTextAttr($value, $data)
    {
        if($data['states']==1)
        {
            return '是';
        }else if($data['states']==0){
            return '否';
        }else{
            return '已过期';
        }
    }


    public function getAddTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }
    
    public function getIntoTimeTextAttr($value, $data)
    {
        if(!empty($data['into_time']))
        {
            $value = $value ? $value : (isset($data['into_time']) ? $data['into_time'] : '');
            return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
        }
        
    }
    
    public function getLeaveTimeTextAttr($value, $data)
    {
        if(!empty($data['leave_time']))
        {
            $value = $value ? $value : (isset($data['leave_time']) ? $data['leave_time'] : '');
            return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;           
        }

    }

}
